package me.hgj.mvvmhelper.widget.state;

import android.app.Activity;
import android.content.Context;
import android.text.InputFilter;
import android.text.Spanned;
import android.util.Log;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;

public final class InputUtil {

    /**
     * 关闭软键盘
     */
    public static void closeKeybord(Activity activity,View editText) {


        try {
            InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
            boolean isOpen = imm.isActive();//isOpen若返回true，则表示输入法打开;
            if (isOpen) {
                imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);//强制关闭
//                imm.showSoftInput(editText, InputMethodManager.SHOW_FORCED);
//                imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
            }
//        }
        } catch (Exception e) {
            Log.e("", e.getMessage(), e);
        }
    }


    public static boolean isOpen(Activity activity) {
        InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
        return imm.isActive();//isOpen若返回true，则表示输入法打开;
    }



}
